package com.atguigu.servlet;

import javax.servlet.*;
import java.io.IOException;

public class Zsh implements Servlet {
    private ServletConfig servletConfig;
    public Zsh() {
        System.out.println("Zsh+---->实例化");
    }
    @Override
    public void init(ServletConfig servletConfig) throws ServletException {
        this.servletConfig=servletConfig;
        System.out.println("Zsh+---->初始化");
        String servletName = servletConfig.getServletName();
        System.out.println("友好名称————》"+servletName);
        String testinitzsh = servletConfig.getInitParameter("testinitzsh");
        System.out.println("servlet的初始化参数__>"+testinitzsh);

        ServletContext servletContext = servletConfig.getServletContext();
        String realPath = servletContext.getRealPath("");
        System.out.println("当前工程的编译路径-->"+realPath);

        String testzshaa = servletContext.getInitParameter("testzshaa");
        System.out.println("当前工程的初始化参数"+testzshaa);

        servletContext.setAttribute("Sccope", "zshde域对象");




    }

    @Override
    public ServletConfig getServletConfig() {
        return null;
    }

    @Override
    public void service(ServletRequest servletRequest, ServletResponse servletResponse) throws ServletException, IOException {
        System.out.println("Zsh+---->服务化");
        servletRequest.getRequestDispatcher("/success.html").forward(servletRequest, servletResponse);


    }

    @Override
    public String getServletInfo() {
        return null;
    }

    @Override
    public void destroy() {
        System.out.println("Zsh+---->销毁");
    }
}
